package com.dly.blog.config;

import com.dly.blog.content.BlogCommon;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/14 16:06
 */
@Configuration
public class RedisFileDelayQueueConfig {

    /**
     * 阻塞队列
     * @param redissonClient
     * @return
     */
    @Bean
    public RBlockingDeque<Long> fileBlockingDeque(RedissonClient redissonClient) {
        return redissonClient.getBlockingDeque(BlogCommon.FILE_DELAY_QUEUE);
    }

    /**
     *  延时队列
     * @param redissonClient the redisson client
     * @return the r delayed queue
     */
    @Bean
    public RDelayedQueue<Long> fileDelayedQueue(RedissonClient redissonClient) {
        //通过阻塞队列来实现延迟队列
        return redissonClient.getDelayedQueue(fileBlockingDeque(redissonClient));
    }

    /**
     * code
     */
    @Bean
    public RBlockingDeque<String> codeBlockingDeque(RedissonClient redissonClient) {
        return redissonClient.getBlockingDeque(BlogCommon.CODE_DELAY_QUEUE);
    }

    /**
     * code
     */
    @Bean
    public RDelayedQueue<String> codeDelayedQueue(RedissonClient redissonClient) {
        //通过阻塞队列来实现延迟队列
        return redissonClient.getDelayedQueue(codeBlockingDeque(redissonClient));
    }
}
